package aom.ju.ss.view.base

import android.app.Activity
import android.app.Dialog
import android.widget.TextView
import aom.ju.ss.R
import aom.ju.ss.utils.LogUtils

/**
 * Created by zc on 2018/3/29.
 *
 *
 * 等待中dialog
 */
class LoadingDialog(context: Activity) {
    private val dialog: Dialog?
    private val tv: TextView
    fun setTvStr(s: String?) {
        if (dialog != null && dialog.isShowing) {
            tv.text = s
        }
    }

    fun dismiss() {
        if (dialog != null && dialog.isShowing) {
            dialog.dismiss()
        }
    }

    init {
        dialog = Dialog(context, R.style.dialog)
        dialog.setContentView(R.layout.dialog_wait)
        tv = dialog.findViewById(R.id.tv_load_dialog)
        dialog.setCanceledOnTouchOutside(false)
        try {
            if (!context.isDestroyed) {
                dialog.show()
            }
        } catch (e: Exception) {
            LogUtils.e(e.message)
        }
    }
}